package com.dapangdong.testdemo.Entiy;

import cn.afterturn.easypoi.entity.ImageEntity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.core.date.DateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * </p>
 *
 * @author : yhd
 * @program: gulimall
 * @since : 2023-04-27 23:18
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class User implements Serializable {

    @Excel(name = "id", type = 10)
    private Long id;

    @Excel(name = "姓名")
    private String name;

    @Excel(name = "年龄", type = 10)
    private Integer age;

    @Excel(name = "分数", type = 10)
    private BigDecimal much;

    @Excel(name = "头像", type = 2, width = 30,height=30, imageType = 1)
    private String image;

    /**
     * 头像
     */
    private ImageEntity imageEntity;

    @Excel(name = "时间", format = "yyyy-MM-dd HH:mm:ss", width = 20)
    private LocalDateTime localDateTime;

    private LocalDate localDate;

    private Date date;

    private DateTime dateTime;

    public static void main(String[] args) {
        // 定义起始日期和结束日期
        LocalDate startDate = LocalDate.of(2022, 6, 1);
        LocalDate endDate = LocalDate.of(2022, 9, 7);

        // 计算两个 LocalDate 对象之间相差的天数
        List<LocalDate> dateRangeA = startDate.datesUntil(endDate.plusDays(1)).collect(Collectors.toList());
        System.out.println(dateRangeA);


        //生成验证码图片
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
        System.out.println(lineCaptcha);
//        try {
//            request.getSession().setAttribute("CAPTCHA_KEY", lineCaptcha.getCode());
//            response.setContentType("image/png");//告诉浏览器输出内容为图片
//            response.setHeader("Pragma", "No-cache");//禁止浏览器缓存
//            response.setHeader("Cache-Control", "no-cache");
//            response.setDateHeader("Expire", 0);
//            lineCaptcha.write(response.getOutputStream());
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        //查询该时间段内的数据
//        LbqWrapper<Entity> wrapper = new LbqWrapper<>();
//        wrapper.geHeader(Entity::getCreateTime, LocalDate.of(2022, 6, 8))
//                .leFooter(Entity::getStorageTime, LocalDate.of(2022, 6, 8));

        LocalDate date = LocalDate.of(2022, 6, 8);
        LocalDate currentDate = LocalDate.now(); // 当前日期
        LocalDate firstDayOfMonth1 = date.withDayOfMonth(1); // 当月第一天
        LocalDate lastDayOfMonth2 = date.withDayOfMonth(1).plusMonths(1).minusDays(1); // 当月最后一天
        System.out.println("当前日期：" + currentDate);
        System.out.println("当月第一天：" + firstDayOfMonth1);
        System.out.println("当月最后一天：" + lastDayOfMonth2);
    }
}
